package logic

import (
	"context"
	"gitee.com/HongXuandaozun/ptwo/pone"

	"gitee.com/HongXuandaozun/ptwo/internal/svc"
	"gitee.com/HongXuandaozun/ptwo/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PtwoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPtwoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PtwoLogic {
	return &PtwoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}

}

func (l *PtwoLogic) Ptwo(req *types.Request) (resp *types.Response, err error) {
	ping, err := l.svcCtx.PoneClient.Ping(l.ctx, &pone.Request{Ping: "来自于：" + req.Name})
	if err != nil {
		logx.Error(err)
		return
	}

	return &types.Response{Message: ping.Pong}, nil
}
